﻿using System;

public abstract class Shape
{
    public abstract double Area
    {
        get;
    }
    public abstract bool isLegal();

}

//正方形
public class Square : Shape
{
    private double mySide;
    public Square(double side)
    {
        this.mySide = side;
    }

    public override double Area
    {
        get
        {
            return mySide*mySide;
        }
    }

    public override bool isLegal()
    {
        return (mySide>0);
    }

    
}


public class Rectangle : Shape
{
    private double width;
    private double height;
    public Rectangle(double width,double height)
    {
        this.width = width;
        this.height = height;
    }
    public override double Area 
    {
        get { return width*height; }
    }

    public override bool isLegal()
    {
        return (width>0&&height>0);
    }
}

//三角形
public class Triangle : Shape
{
    private double a;
    private double b;
    private double c;
    private double p;
    public Triangle(double a,double b,double c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        p = (a+b+c)/2;
    }
    public override double Area
    {
        get { return Math.Sqrt(p*(p-a)*(p-b)*(p-c)); }
    }

    public override bool isLegal()
    {
        return a+b>c&&a+c>b&&b+c>a;
    }



   
}



public class Text
{
    public static void Main(String[] args)
    {
        Shape[] shapes =
        {
            new Triangle(56,33,84),
            new Square(98),
            new Rectangle(39,21),
            new Triangle(28,43,17),
            new Triangle(67,47,32),
            new Rectangle(89,21),
            new Square(89),
            new Rectangle(78,92),
            new Square(21),
            new Rectangle(29,91)
        };
        bool flag = true;
        foreach (Shape shape in shapes)
        {
            if (!shape.isLegal())
            {
                flag = false;
            }
        }
        if (flag)
        {
            Console.WriteLine("十个图形的面积和是：");
            double s = 0;
            foreach (Shape shape in shapes)
            {
                s+=shape.Area;
            }
            Console.WriteLine(s);
        }
        else
        {
            Console.WriteLine("图形输入不合法");
        }
        
    }
}

